#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QLabel* label1 = new QLabel(ui->tab);
    label1->setText("this is tab1");
    QLabel* label2 = new QLabel(ui->tab_2);
    label2->setText("this is tab2");
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_tabWidget_currentChanged(int index)
{
    qDebug() << "current tab is tab" + QString::number(index + 1);
}

void Widget::on_pushButton_clicked()
{
    QWidget* w = new QWidget();
    int count = ui->tabWidget->count();
//    int curIndex = ui->tabWidget->currentIndex();
    QLabel* label = new QLabel(w);
    label->setText("this is tab" + QString::number(count + 1));
    ui->tabWidget->addTab(w,"Tab " + QString::number(count + 1));
    ui->tabWidget->setCurrentIndex(count);
}

void Widget::on_pushButton_2_clicked()
{
    int index = ui->tabWidget->currentIndex();
    ui->tabWidget->removeTab(index);
}
